﻿using System;
using System.Linq;
using Trains.DTO;
using Trains.Models.Interfaces;
using Trains.Services.Interface;

namespace Trains.Services
{
    public class StationService: IStationService
    {
        private IStationDomainService _stationDomainService;

        public StationService(IStationDomainService stationDomainService)
        {
            _stationDomainService = stationDomainService;
        }

        public string GetDistanceByRoute(string route)
        {
            var stations = route.Split('-').ToList();
            var distance = _stationDomainService.GetDistanceByRoute(stations);

            return distance;
        }

        public string GetNumberOfTripsByFilter(string fromName, string toName, OperationType operationType, int stops)
        {
            var result = _stationDomainService.GetNumberOfTrip(fromName, toName, operationType, stops);

            return result.ToString();
        }

        public string GetShortestRoute(string fromName, string toName)
        {
            //the station count
            var maxStops = 5;
            var result = _stationDomainService.GetShortestRoute(fromName, toName, maxStops);

            return result.ToString();
        }

        public string GetNumberOfTripWithDistance(string fromName, string toName, int distance)
        {
            //the min distance in one route
            var maxStops = distance / 2;
            var result = _stationDomainService.GetNumberOfTripWithDistance(fromName, toName, distance, maxStops);

            return result.ToString();
        }
    }
}
